<?php
/**
 * session库
 * @copyright	http://www.easymvc.com
 * @author 		光哥 <439884988@qq.com>
 * @version		1.0 - 2012-07-02
 * @package		Lib
 */
if(!defined('EASYMVC')) {
	exit('Access Denied');
}
/**
 * session 存储 
 */
class Lib_Session
{
    private $sessionState = false;
    protected $session_cache_expire = 30;
    
    /**
     * 开启session
     * 
     * @return boolean
     */
    function __construct() {
    
    	session_cache_expire($this->session_cache_expire);
    
    	$this->sessionState = session_start();
    	
    	return $this->sessionState;
	}
    
    
    /**
    *    实例化对象
    *    
    *    @return  object
    **/
    
	public static function getInstance(){
			static $obj;
			if(!$obj) $obj =  new self();
			return $obj;
	}
    
    
   /**
    * set 变量
    * @param string $name
    * @param string|int|array $value
    * @return void
    */
    
    public function set( $name , $value )
    {
        $_SESSION[$name] = $value;
    }
    
    /**
     * 获取变量
     * @param string  $name
     * @return sring|int|array
     */
    
    public function get( $name )
    {
        if ( isset($_SESSION[$name]))
        {
            return $_SESSION[$name];
        }
    }
    
    /**
     * 判断key 是否存在
     * @param string $name
     * @return boolean
     */
    public function is_set( $name )
    {
        return isset($_SESSION[$name]);
    }
    
    /**
     * 删除
     * @param string $name
     */
    public function del( $name )
    {
        unset( $_SESSION[$name] );
    }
    
    
    /**
    *    清楚session
    *    
    *    @return    boolean
    **/
    
    public function destroy()
    {
        if ($this->sessionState)
        {	
            $this->sessionState = !session_destroy();
            unset($_SESSION );
            return true;
        }
        
        return FALSE;
    }
}
?>